package com.mingye.model;

import java.util.Objects;

/**
 * 基本元素
 *
 * @author daixinyi
 */
public abstract class Element {

    protected int x;

    protected int y;

    protected String imagePath;


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    public void setLocation(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * 重写equals方法，两个对象的x坐标，y坐标相同则认为两个对象相等
     *
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Element element = (Element) o;
        return x == element.x && y == element.y;
    }

    /**
     * 重写hashCode方法，两个对象的x坐标，y坐标相同则认为两个对象相等
     *
     * @return
     */
    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}
